home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d8 / pdriver5.arc / TERMIN.ASM < prev    next >
Assembly Source File  |  1989-12-17  |  4KB  |  185 lines

  1. ;  Russell Nelson, Clarkson University.  October 20, 1988
  2. ;  Copyright, 1988, 1989, Russell Nelson
  3.  
  4. ;   This program is free software; you can redistribute it and/or modify
  5. ;   it under the terms of the GNU General Public License as published by
  6. ;   the Free Software Foundation, version 1.
  7. ;
  8. ;   This program is distributed in the hope that it will be useful,
  9. ;   but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. ;   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11. ;   GNU General Public License for more details.
  12. ;
  13. ;   You should have received a copy of the GNU General Public License
  14. ;   along with this program; if not, write to the Free Software
  15. ;   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16.  
  17. segmoffs    struc
  18. offs        dw    ?
  19. segm        dw    ?
  20. segmoffs    ends
  21.  
  22. HT    equ    09h
  23. CR    equ    0dh
  24. LF    equ    0ah
  25.  
  26. code    segment byte public
  27.     assume    cs:code, ds:code
  28.  
  29.     org    80h
  30. phd_dioa    label    byte
  31.  
  32.     org    100h
  33. start:
  34.     jmp    start_1
  35.  
  36. their_isr    dd    ?
  37. packet_int_no    db    ?,?
  38. signature    db    'PKT DRVR',0
  39. signature_len    equ    $-signature
  40. no_signature_msg    db    "No packet driver at that address",'$'
  41. usage_msg    db    "usage: termin <packet_int_no>",'$'
  42.  
  43. usage_error:
  44.     mov    dx,offset usage_msg
  45. error:
  46.     mov    ah,9
  47.     int    21h
  48.     int    20h
  49.  
  50. start_1:
  51.     mov    si,offset phd_dioa+1
  52.     cmp    byte ptr [si],CR    ;end of line?
  53.     je    usage_error
  54.  
  55.     mov    di,offset packet_int_no
  56.     call    get_number
  57.  
  58.     mov    ah,35h            ;get their packet interrupt.
  59.     mov    al,packet_int_no
  60.     int    21h
  61.     mov    their_isr.offs,bx
  62.     mov    their_isr.segm,es
  63.  
  64.     lea    di,3[bx]
  65.     mov    si,offset signature
  66.     mov    cx,signature_len
  67.     repe    cmpsb
  68.     jne    no_signature_err
  69.  
  70.     mov    ah,5            ;terminate the driver.
  71.     mov    bx,0
  72.     pushf
  73.     cli
  74.     call    their_isr
  75.  
  76.     int    20h
  77.  
  78. no_signature_err:
  79.     mov    dx,offset no_signature_msg
  80.     mov    ah,9
  81.     int    21h
  82.     int    20h
  83.  
  84.  
  85.     public    get_number
  86. get_number:
  87.     mov    bp,10            ;we default to 10.
  88.     jmp    short get_number_0
  89.  
  90.     public    get_hex
  91. get_hex:
  92.     mov    bp,16
  93. ;get a hex number from [si], skipping leading blanks.
  94. ;return cy if there are no digits at all.
  95. ;return nc, bx:cx = number, and store cx at [di]
  96. get_number_0:
  97.     call    skip_blanks
  98.     call    get_digit        ;is there really a number here?
  99.     jc    get_number_3
  100.     or    al,al            ;Does the number begin with zero?
  101.     jne    get_number_4        ;no.
  102.     mov    bp,8            ;yes - they want octal.
  103. get_number_4:
  104.  
  105.     xor    cx,cx            ;get a hex number.
  106.     xor    bx,bx
  107. get_number_1:
  108.     lodsb
  109.     cmp    al,'x'            ;did they really want hex?
  110.     je    get_number_5        ;yes.
  111.     cmp    al,'X'            ;did they really want hex?
  112.     je    get_number_5        ;yes.
  113.     call    get_digit        ;convert a character into an int.
  114.     jc    get_number_2        ;not a digit (neither hex nor dec).
  115.     xor    ah,ah
  116.     cmp    ax,bp            ;larger than our base?
  117.     jae    get_number_2        ;yes.
  118.  
  119.     push    ax            ;save the new digit.
  120.  
  121.     mov    ax,bp            ;multiply the low word by ten.
  122.     mul    cx
  123.     mov    cx,ax            ;keep the low word.
  124.     push    dx            ;save the high word for later.
  125.     mov    ax,bp
  126.     mul    bx
  127.     mov    bx,ax            ;we keep only the low word (which is our high word)
  128.     pop    dx
  129.     add    bx,ax            ;add the high result from earlier.
  130.  
  131.     pop    ax            ;get the new digit back.
  132.     add    cx,ax            ;add the new digit in.
  133.     adc    bx,0
  134.     jmp    get_number_1
  135. get_number_5:
  136.     mov    bp,16            ;change the base to hex.
  137.     jmp    get_number_1
  138. get_number_2:
  139.     dec    si
  140.     mov    [di],cx            ;store the parsed number.
  141.     clc
  142.     ret
  143. get_number_3:
  144.     stc
  145.     ret
  146.  
  147.  
  148.     public    skip_blanks
  149. skip_blanks:
  150.     lodsb                ;skip blanks.
  151.     cmp    al,' '
  152.     je    skip_blanks
  153.     cmp    al,HT
  154.     je    skip_blanks
  155.     dec    si
  156.     ret
  157.  
  158.  
  159. get_digit:
  160. ;enter with al = character
  161. ;return nc, al=digit, or cy if not a digit.
  162.     cmp    al,'0'            ;decimal digit?
  163.     jb    get_digit_1        ;no.
  164.     cmp    al,'9'            ;. .?
  165.     ja    get_digit_2        ;no.
  166.     sub    al,'0'
  167.     clc
  168.     ret
  169. get_digit_2:
  170.     or    al,20h
  171.     cmp    al,'a'            ;hex digit?
  172.     jb    get_digit_1
  173.     cmp    al,'f'            ;hex digit?
  174.     ja    get_digit_1
  175.     sub    al,'a'-10
  176.     clc
  177.     ret
  178. get_digit_1:
  179.     stc
  180.     ret
  181.  
  182. code    ends
  183.  
  184.     end    start
  185.